#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define N 1000006
int gx[4]={0,0,-1,1},gy[4]={-1,1,0,0},can[N],e[N];char c[N];int n,m;
inline int getsum(int v){
	int x=v/m+1,y=(v-1)%m+1;
	if(!e[v])	return 0;
	for(int i=0;i<4;i++){
		int x1=x+gx[i],y1=y+gy[i],val=m*(x1-1)+y1;
		if(x1<1||y1<1||x1>n||y1>m)	continue;
		if(c[val]=='.')	continue;
		if(!e[val])	return 0;
	}
	return 1;
}
inline void getad(int v,int ad){
	int x=v/m+1,y=(v-1)%m+1;e[v]+=ad;
	for(int i=0;i<4;i++){
		int x1=x+gx[i],y1=y+gy[i],val=m*(x1-1)+y1;
		if(x1<1||y1<1||x1>n||y1>m)	continue;
		if(c[val]=='.')	continue;
		e[val]+=ad;
	}
}
signed main(){
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n*m;i++){
		cin>>c[i];if(c[i]=='#')	can[i]=1;
	}
	for(int i=1;i<=n*m;i++){
		if(can[i])	getad(i,1);
	}
	for(int i=1;i<=n*m;i++){
		if(c[i]=='.')	continue;
		getad(i,-1);
		if(!getsum(i)){
			getad(i,1);continue;
		}
		can[i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c[(i-1)*m+j]=='.'){
				cout<<".";continue;
			}
			cout<<can[(i-1)*m+j];
		}cout<<"\n";
	}
	return 0;
}

